<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Comment model
 */
class Comment_model extends MY_Model{

	public function __construct()
	{
		parent::__construct();
	}

	public function create($data = array())
	{
		$this->db->insert('_comment', $data);
	}

	/**
	 * İçeriğe yapılan yorumları getirir
	 * @param int yorumları istenen içeriğin id si
	 */
	public function getsById($id)
	{
		$this
			->gets()
			->where('c.relation_id', $id);
			
		return parent::my_result();
	}

	private function gets($limit = 0, $offset = 0)
	{
		return $this->db
			->select('SQL_CALC_FOUND_ROWS c.*, u.username', FALSE)
			->from('comment AS c')
			->join('user AS u', 'c.user_id = u.id');
	}

	/**
	 * Created comment form
	 *
	 * @param int relation_id
	 * @return string
	 */
	public function show_form($relation_id)
	{
		$data = array(
			'relation_id' => $relation_id
		);

		$this->load->view('frontend/comment/form', $data);
	}
}

/* End of file comment_model.php */
